<?php defined('SYSPATH') or die('No direct script access.');

/**
 * 支付宝小程序相关接口,接收小程序的支付调用
 * Class Controller_Pc_Api_V2_Payment_Wechatapp
 */
class Controller_Pc_Api_V2_Payment_Zhifubao extends Controller_Pc_Api_v2_Base
{
    // 数据请求结果
    private $result;

    /**
     * 参数验证对象
     * @var Request_Api_V2_Payment_Zhifubao
     */
    private $validation;

    /**
     * 支付服务
     * @var Service_Api_Payment_Zhifubao
     */
    private $service;

    public function before()
    {
        parent::before();

        // 返回数据
        $this->result = array(
            'status' => true,//默认状态为成功
            'msg' => '操作成功',//默认的提示消息
            'data' => array()
        );
        // 验证类实例化
        $this->validation = Request_Api_V2_Factory::create('payment_zhifubao', $this->request_params);
        //酒店服务
        $this->service = new Service_Api_Payment_Zhifubao();
    }

    public function after()
    {
        $this->send_datagrams($this->client_info['id'], $this->result, $this->client_info['secret_key']);
    }

    /**
     * 支付数据
     */
    public function action_get_pay_data()
    {
        try {
            $this->validation->get_pay_data()->check();
            $data = $this->service->get_pay_data($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }
}